package com.piece.core.pay.client.impl.wxpay;

import com.piece.core.pay.client.PayClientConfig;
import lombok.Data;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.validation.constraints.NotBlank;
import java.io.InputStream;
import java.util.Set;

/**
 * 微信支付的 PayClientConfig 实现类
 */
@Data
public class WXPayClientConfig implements PayClientConfig {

    /**
     * API 版本 - V3
     * https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay-1.shtml
     */
    public static final String API_VERSION_V3 = "v3";

    /**
     * 公众号或者小程序的 appid
     */
    @NotBlank(message = "APPID 不能为空", groups = {V3.class})
    private String appId;

    /**
     * 商户号
     */
    @NotBlank(message = "商户号 不能为空", groups = {V3.class})
    private String mchId;

    /**
     * API 版本
     */
    @NotBlank(message = "API 版本 不能为空", groups = {V3.class})
    private String apiVersion = API_VERSION_V3;

    /**
     * apiclient_key.pem 证书文件
     */
    @NotBlank(message = "privateKey 不能为空", groups = V3.class)
    private InputStream privateKey;

    /**
     * apiclient_cert.pem 证书文件
     */
    @NotBlank(message = "privateCert 不能为空", groups = V3.class)
    private InputStream privateCert;

    /**
     * apiV3 密钥值
     */
    @NotBlank(message = "apiV3 密钥值 不能为空", groups = V3.class)
    private InputStream apiV3Key;

    /**
     * 异步回调地址
     */
    @NotBlank(message = "异步回调地址 不能为空", groups = V3.class)
    private String notifyUrl;

    /**
     * 支付回调地址
     */
    @NotBlank(message = "支付回调地址 不能为空", groups = V3.class)
    private String returnUrl;

    /**
     * 退款回调地址
     */
    @NotBlank(message = "退款回调地址 不能为空", groups = V3.class)
    private String refundUrl;

    /**
     * 分组校验 v3版本
     */
    public interface V3 {
    }

    @Override
    public Set<ConstraintViolation<PayClientConfig>> verifyParam(Validator validator) {
        return validator.validate(this, V3.class);
    }
}
